Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DPTBase.get_dpt DPT definition helper classmethod #1652

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

farmio
Copy link
Member

@farmio farmio commented Feb 8, 2025

Description

This accepts int, string, dict ({"main": int, "sub": int | None}) or DPT classes. It raises ValueError if no usable subclass is found.

Examples:

x = DPTBase.get_dpt(16)
reveal_type(x)  # -> type[DPTBase]

y = DPTNumeric.get_dpt(16)  # raises ValueError since DPT 16 is not Numeric
reveal_type(y)  # -> type[DPTNumeric]

DPTBase.get_dpt(DPTNumeric)  # raises ValueError since DPTNumeric is abstract (not a DPT definition, but a category of definitions)

DPTBase.get_dpt(DPTString)  # -> DPTString

DPTEnum.get_dpt({"main": 1, "sub": 8})  # -> DPTUpDown

cc @philippwaller
Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code quality improvements to existing code or addition of tests

Checklist

  • The documentation has been adjusted accordingly
  • Tests have been added that prove the fix is effective or that the feature works
  • The changes are documented in the changelog (docs/changelog.md)

Copy link

codecov bot commented Feb 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.93%. Comparing base (6d545f7) to head (614e8b8).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1652   +/-   ##
=======================================
  Coverage   96.92%   96.93%           
=======================================
  Files         160      160           
  Lines       10702    10718   +16     
=======================================
+ Hits        10373    10389   +16     
  Misses        329      329           
Files with missing lines Coverage Δ
xknx/core/group_address_dpt.py 97.82% <100.00%> (+0.04%) ⬆️
xknx/devices/expose_sensor.py 100.00% <100.00%> (ø)
xknx/devices/notification.py 100.00% <100.00%> (ø)
xknx/devices/numeric_value.py 100.00% <100.00%> (ø)
xknx/devices/sensor.py 100.00% <100.00%> (ø)
xknx/dpt/dpt.py 100.00% <100.00%> (ø)
xknx/remote_value/remote_value_sensor.py 100.00% <100.00%> (ø)
xknx/tools/group_communication.py 97.67% <100.00%> (-0.33%) ⬇️
xknx/typing/__init__.py 100.00% <100.00%> (ø)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant